package be.novelfaces.component.input;

import javax.faces.component.UIComponent;
import javax.faces.component.UIOutput;
import javax.faces.component.behavior.ClientBehaviorHolder;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
import javax.faces.render.Renderer;

import be.novelfaces.component.util.RenderUtils;
import be.novelfaces.component.util.RenderUtilsFactory;

public abstract class AbstractInputRenderer extends Renderer {

	@Override
	public void decode(FacesContext facesContext, UIComponent component) {
		RenderUtils renderUtils = RenderUtilsFactory.getInstance();

		renderUtils.checkParamValidity(facesContext, component, null);

		renderUtils.decodeUIInput(facesContext, component);
		if (component instanceof ClientBehaviorHolder
				&& !renderUtils.isDisabled(component)) {
			renderUtils.decodeClientBehaviors(facesContext, component);
		}
	}

	@Override
	public Object getConvertedValue(FacesContext facesContext,
			UIComponent component, Object val) throws ConverterException {
		RenderUtils renderUtils = RenderUtilsFactory.getInstance();
		renderUtils.checkParamValidity(facesContext, component, UIOutput.class);
		return renderUtils.getConvertedUIOutputValue(facesContext,
				(UIOutput) component, val);
	}

}